package com.hst.capacity.domain.service.impl;

import com.hst.capacity.domain.model.entity.auth.TcAuthEntity;
import com.hst.capacity.domain.service.AuthService;
import com.hst.capacity.infra.persistence.jpa.auth.TcAuthRepository;
import com.hst.capacity.infra.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AuthServiceImpl implements AuthService {

    @Autowired
    TcAuthRepository tcAuthRepository;

    @Override
    public String findIdChannel(String tenant, String idFranchisee) {
        String idChannel = null;
        if (StringUtil.isNotBlank(tenant))
            idChannel = tenant;
        List<TcAuthEntity> list = tcAuthRepository.findByIdFranchiseeAndClientType(idFranchisee, 10);
        TcAuthEntity tcAuthEntity;
        if (list != null && list.size() > 0) {
            tcAuthEntity = list.get(0);
            idChannel = tcAuthEntity.getIdChannel();
        }
        return idChannel;
    }

    @Override
    public List<String> findIdFranchiseeByIdChannel(String idChannel) {
        return tcAuthRepository.findIdFranchiseeByIdChannel(idChannel);
    }

    @Override
    public TcAuthEntity findByIdChannelAndRegionCode(String idChannel, String regionCode) {
        return tcAuthRepository.findByIdChannelAndRegionCode(idChannel, regionCode);
    }

}
